package com.jspgou.cms.action.store;

import static com.jspgou.cms.Constants.STORE_SYS;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jspgou.cms.entity.Report;
import com.jspgou.cms.entity.ShopMember;
import com.jspgou.cms.entity.Store;
import com.jspgou.cms.manager.ReportMng;
import com.jspgou.cms.web.CmsUtils;
import com.jspgou.cms.web.ShopFrontHelper;
import com.jspgou.cms.web.SiteUtils;
import com.jspgou.common.web.springmvc.MessageResolver;
import com.jspgou.core.entity.Website;

@Controller
public class ReportAct {
     
 	/**
 	 * 店铺投诉举报处理页
 	 */
 	private static final String TPL_REPORT_STORE_HANDLE="tpl.reportStoreHandle";
 	/**
 	 * 店铺投诉举报列表页
 	 */
 	private static final String TPL_REPORT_STORE_LIST="tpl.reportStoreList";
 	/**
 	 * 店铺查看投诉举报页
 	 */
 	private static final String TPL_REPORT_SOTER_VIEW="tpl.reportStoreView";
 	
 	
    @RequestMapping(value="/report/list.jspx")
    public String refundList(String cl,Integer pageNo,HttpServletRequest request,
   		 HttpServletResponse response,ModelMap model){
   	 Website web=SiteUtils.getWeb(request);
   	 ShopMember member=CmsUtils.getMember(request);
   	 //用户没有登录，跳转到登录页
   	 if(member==null){
   		 return ShopFrontHelper.showLogin(request, model, web);
   	 }
   	 Store store=null;
   	 if(member.getStore()!=null){
   		store=member.getStore();
   	 }
	 model.addAttribute("store", store);
	 model.addAttribute("cl", cl);
   	 ShopFrontHelper.setCommonData(request, model, web);
   	 ShopFrontHelper.frontPageData(request, model);
   	 return web.getTplSys(STORE_SYS, MessageResolver.getMessage(request,TPL_REPORT_STORE_LIST), request);
    }
    
    @RequestMapping(value="/report/view.jspx")
    public String refundView(Long id,HttpServletRequest request,
   		 HttpServletResponse response,ModelMap model){
   	 Website web=SiteUtils.getWeb(request);
   	 ShopMember member=CmsUtils.getMember(request);
   	 //用户没有登录，跳转到登录页
   	 if(member==null){
   		 return ShopFrontHelper.showLogin(request, model, web);
   	 }
   	 Report bean=manager.findById(id);
   	 model.addAttribute("report", bean);
   	 model.addAttribute("member", member);
   	 model.addAttribute("order", bean.getOrder());
   	 ShopFrontHelper.setCommonData(request, model, web);
   	 ShopFrontHelper.frontPageData(request, model);
   	 return web.getTplSys(STORE_SYS, MessageResolver.getMessage(request,TPL_REPORT_SOTER_VIEW), request);
    }
 	
     @RequestMapping(value="/report/handle.jspx")
     public String refundApply(Long id,HttpServletRequest request,
    		 HttpServletResponse response,ModelMap model){
    	 Website web=SiteUtils.getWeb(request);
    	 ShopMember member=CmsUtils.getMember(request);
    	 //用户没有登录，跳转到登录页
    	 if(member==null){
    		 return ShopFrontHelper.showLogin(request, model, web);
    	 }
    	 Report bean =manager.findById(id);
    	 model.addAttribute("report", bean);
    	 model.addAttribute("order", bean.getOrder());
    	 ShopFrontHelper.setCommonData(request, model, web);
    	 ShopFrontHelper.frontPageData(request, model);
    	 return web.getTplSys(STORE_SYS, MessageResolver.getMessage(request,TPL_REPORT_STORE_HANDLE), request);
     }
     
     @RequestMapping(value="/report/update.jspx")
     public String applySave(Report bean,HttpServletRequest request,
    		 HttpServletResponse response,ModelMap model){
    	 Website web=SiteUtils.getWeb(request);
    	 ShopMember member=CmsUtils.getMember(request);
    	 //用户没有登录，跳转到登陆页
    	 if(member==null){
    		 return ShopFrontHelper.showLogin(request, model, web);
    	 }
    	 bean.setEndDate(new Date());
    	 manager.update(bean);
    	 return "redirect:list.jspx";
     }

     @Autowired
     private ReportMng manager;

	
}
